import java.util.*;

public class SensorManagerImpl implements SensorManager {

    private Map<String, Map<Date, Object>> sensorDataMap;
    private Map<String, String> sensorTypeMap;

    public static void main(String[] args) {
//        Map<Date, Object> dataMap = sensorDataMap.get("Greggs common.queue");
//        int sum = 0;
//        int size = 0;
//        for (Object object : dataMap.values()) {
//            if (object != null) {
//                sum += Integer.parseInt(object.toString());
//                size++;
//            }
//        }
//        double average = size > 0 ? sum * 1.0 / size : 0;
//
//
//        List<String> roomList = new ArrayList<>();
//        for (String sensor : sensorTypeMap.keySet()) {
//            if (sensorTypeMap.get(sensor).equals("RoomUsageSensor")) {
//                Map<Date, Object> dataMap = sensorDataMap.get(sensor);
//                if (dataMap != null && dataMap.size() > 0) {
//                    List<Object> values = new ArrayList<>(dataMap.values());
//                    Boolean occupied = (Boolean) values.get(values.size() - 1);
//                    if (occupied) {
//                        roomList.add(sensor);
//                    }
//                }
//            }
//        }
//        System.out.println(roomList);




    }

    public SensorManagerImpl() {
        sensorTypeMap = new HashMap<>();
    }

    public void addSensor(Sensor sensor) {
        sensorTypeMap.put(sensor.getName(), sensor.getClass().getSimpleName());
        sensorDataMap = new HashMap<>();
    }

    public <T> void receiveDate(String sensor, Map<Date, T> recordMap) {
        Map<Date, Object> map = sensorDataMap.get(sensor);
        if (map == null) {
            map = new LinkedHashMap<>();
            sensorDataMap.put(sensor, map);
        }
        map.putAll(recordMap);
    }

    @Override
    public void dataReceived(String sensor, Object data) {
        Map<Date, Object> map = sensorDataMap.get(sensor);
        if (map == null) {
            map = new HashMap<>();
            sensorDataMap.put(sensor, map);
        }
        map.put(new Date(), data);
    }
}
